package com.dhcc.sds.standard.controller;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.sds.standard.dto.SdsStandDicCompDto;
import com.dhcc.sds.standard.dto.SdsStandStaDto;
import com.dhcc.sds.standard.entity.SdsStandSourceEntity;
import com.dhcc.sds.standard.service.ISdsStandDicCompStaService;
import com.dhcc.sds.standard.service.ISdsStandDicService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  数据字典对照统计
 */
@Controller
@RequestMapping(value = "${sys.backendPath}/sds/sdsstanddiccompsta")
public class SdsStandDicCompStaController {

    private String PREFIX = "/backend/sds/sdsstanddiccompsta/";

    @Autowired
    private ISdsStandDicCompStaService standDicCompStaService;
    @Autowired
    private ISdsStandDicService standDicService;

    @RequestMapping("")
    public String index(Model model) {
        JSONArray dicRoot = standDicService.getDicRoot();
        model.addAttribute("dicRoot",dicRoot);
        return PREFIX + "sdsstanddiccompsta.html";
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false)Map<String,Object> params){
        Page<SdsStandStaDto> page = new PageFactory<SdsStandStaDto>().defaultPage();
        List<SdsStandStaDto> result = this.standDicCompStaService.page(page,params);
        page.setRecords((List<SdsStandStaDto>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    @RequestMapping("/to_detail/{id}/{type}")
    public String toDetail(@PathVariable Long id, @PathVariable String type, Model model) {
        Map<String, Object> searchTypeMap = new HashMap<>();
        searchTypeMap.put("matched", "已关联");
        searchTypeMap.put("noMatch", "未关联");
        model.addAttribute("searchTypeMap", searchTypeMap);
        model.addAttribute("id", id);
        model.addAttribute("type", type);
        return PREFIX + "sdsstanddiccompdetail.html";
    }

    @RequestMapping(value = "/dictMatchList")
    @ResponseBody
    public Object dictCompList(@RequestParam(required = false)Map<String,Object> params){
        Page<SdsStandDicCompDto> page = new PageFactory<SdsStandDicCompDto>().defaultPage();
        List<SdsStandDicCompDto> result = this.standDicCompStaService.dictMatchPage(page, params);
        page.setRecords((List<SdsStandDicCompDto>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }
}
